Added a debug log to investigate #8685, as it worksforme. Refs #8685
[adiumx.git] / unittest runner.applescript
blob8a3471f138a0a669a41d6520cc8196027739550b
1 (* Read Me.
3 This is the unit test runner for AppleScript. In order to run them from the command line, in adium/ folder, use
4 osascript unittest\ runner.applescript
5 piped to
6 tr '\r' '\n'
8 For some reason, Script Editor doesn't like the pipe character...
10 Anyway, this will compile and run the AppleScripts in ASUnitTests and report the results. The tr translates the old Mac CR to Unix LF. You should see Adium leap about while this is happening. Every unit test should clean up after itself, so that no windows are left lying around, extra accounts existing, etc.
12 The runner will report if any tests failed and the error number and message. It will also summarize with a number succeeded out of the total number.
15 property unitTestDir : "ASUnitTests/"
17 script HandyAdiumScripts
18 property defaultService : "AIM"
19 property defaultAccount : "applmak"
20 property defaultParticipant : "applmak"
21 property otherParticipant : "boredzo"
22 on makeTemporaryAccount()
23 tell application "Adium"
24 tell service defaultService
25 return make new account with properties {title:"test"}
26 end tell
27 end tell
28 end makeTemporaryAccount
29 on makeNewChatWindow()
30 tell application "Adium"
31 set newChat to my makeNewChat()
32 return (get window of newChat)
33 end tell
34 end makeNewChatWindow
35 on makeNewChat()
36 tell application "Adium"
37 tell account defaultAccount
38 set newChat to make new chat with contacts {my findSomeParticipant()} with new chat window
39 end tell
40 return newChat
41 end tell
42 end makeNewChat
43 on findSomeParticipant()
44 tell application "Adium"
45 tell account defaultAccount
46 if exists contact defaultParticipant then
47 return contact defaultParticipant
48 else
49 if (count contacts) > 1 then
50 return some contact
51 else
52 -- we're offline?
53 error "Can't get any contacts because account is offline."
54 return missing value
55 end if
56 end if
57 end tell
58 end tell
59 end findSomeParticipant
60 on cleanup()
61 tell application "Adium"
62 repeat while exists chat window 1
63 close chat window 1
64 end repeat
65 end tell
66 end cleanup
67 end script
69 on run
70 --compile the .applescript files
71 do shell script "for i in " & quoted form of unitTestDir & "*.applescript; do s=`basename $i .applescript`; osacompile -o " & quoted form of unitTestDir & "/${s}.scpt " & quoted form of unitTestDir & "/${s}.applescript ; done;"
72 --get contents of unitTestDir
73 tell application "Finder"
74 set unittestScripts to every file of folder ((POSIX file unitTestDir) as text) whose name extension is "scpt"
75 set report to ""
76 set successReport to ""
77 set total to 0
78 set failed to 0
79 set startTime to current date
80 repeat with s in unittestScripts
81 set nameOfS to (get name of s)
82 --do any set up or takedown
83 --For speed concerns, I'm going to assume that a unit test will do these
84 try
85 set unittest to load script file ((((POSIX file unitTestDir) as text) & nameOfS))
86 try
87 set total to total + 1
88 tell unittest to run
89 set successReport to successReport & nameOfS & ": Success!" & return
90 on error msg number num
91 set failed to failed + 1
92 if num is -2700 then
93 --assertion failed!
94 set report to report & nameOfS & ": " & "Assertion Failed: " & num & ": " & msg & return
95 else
96 --some exception
97 set report to report & nameOfS & ": " & "Unexpected Exception: " & num & ": " & msg & return
98 end if
99 end try
100 on error
101 set report to report & nameOfS & ": " & "Error Loading Script!" & return
102 end try
103 end repeat
104 end tell
105 set report to "Number Of Successes/Total: " & (total - failed) & "/" & total & return & "Time: " & ((current date) - startTime) & "s" & return & report & "-----" & return & successReport
106 report
107 end run